package leetcode.ge100;

import leetcode.lt100.TreeNode;

import java.util.ArrayList;
import java.util.List;

class Solution_102 {

    public List<List<Integer>> levelOrder(TreeNode root) {
        return levelOrder(0, root, new ArrayList<>());
    }

    private List<List<Integer>> levelOrder(int index, TreeNode root, List<List<Integer>> res) {
        if (root != null) {
            if (res.size() <= index)
                res.add(new ArrayList<>());
            res.get(index).add(root.val);
            levelOrder(index + 1, root.left, res);
            levelOrder(index + 1, root.right, res);
        }
        return res;
    }

}